import {
  STORE_INFO_PAGE,
  STORE_INFO_UPDATE,
  STORE_INFO_SAVE,
  STORE_PIC_UPLOAD,
  METRO,
  STORE_INFO_DOWN
} from '@/services/api'
import axios from 'axios'

import { request, METHOD } from '@/utils/request'
import Cookie from 'js-cookie'
const BASE_URL = process.env.VUE_APP_API_URL

/**
 * 门店列表
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function StoreInfo (params) {
  return request(STORE_INFO_PAGE, METHOD.GET, params)
}

export async function StoreInfoSelect (params) {
  return request(`${BASE_URL}/business/admin/vehicleLock/audit/store/list`, METHOD.GET, params)
}
// 品牌查询
export async function getBrandsByType (params) {
  return request(`${BASE_URL}/business/admin/brands/getBrandsByType`, METHOD.GET, params)
}
// 变更车辆所在门店

export async function getRegularDinnerUnchecked (params) {
  return request(`${BASE_URL}/order/hq/admin/regularDinner/getRegularDinnerUnchecked`, METHOD.GET, params)
}

/**
 * 门店下架
 * @returns {Promise<AxiosResponse<T>>}
 */

export async function StoreDown (id) {
  return request(`${STORE_INFO_DOWN}${id}`, METHOD.DELETE)
}
export async function StoreUp (id) {
  return request(`${BASE_URL}/business/admin/stores/upStore/${id}`, METHOD.POST)
}

/**
 * 上传门店照片
 * @returns {Promise<AxiosResponse<T>>}
 */
export function StoreUpload (data) {
  return STORE_PIC_UPLOAD
}
export function StoreUploadImage (data) {
  return `${BASE_URL}/business/admin/vehicleDeviceInfo/uploadImage`
}
export function StoreUploadImageVinNo (data) {
  return `${BASE_URL}//business/admin/vehicleShelfInfo/uploadImage`
}
export function StoreUploadLogo (data) {
  return `${STORE_PIC_UPLOAD}Logo`
}
/**
 * 门店新增
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function StoreAdd (params) {
  return request(STORE_INFO_SAVE, METHOD.POST, params)
}

/**
 * 门店修改
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function StoreEdit (params) {
  return request(STORE_INFO_UPDATE, METHOD.POST, params)
}

/**
 * 地铁商圈
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function MetroList (params) {
  return request(METRO, METHOD.GET, params)
}

// 门店信息
export async function storesIdGet (id) {
  return request(`${BASE_URL}/business/admin/stores/${id}`, METHOD.GET)
}

export async function dictTree (type) {
  return request(`${BASE_URL}/business/admin/dict/${type}/tree`, METHOD.GET)
}
// 新增门店

export async function addStore (data) {
  return request(`${BASE_URL}/business/admin/stores`, METHOD.POST, data)
}
// 门店修改
export async function editStore (id, data) {
  return request(`${BASE_URL}/business/admin/stores/${id}`, METHOD.PUT, data)
}
// 门店信息回显
export async function getStore (id) {
  return request(`${BASE_URL}/business/admin/stores/${id}`, METHOD.GET)
}
// 门店导入
export const storeTemplate = () => {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    url: `${BASE_URL}/business/admin/storeInfo/import/getStoreInfosFilterExcelTemplate`,
    responseType: 'blob'
  })
}
// 门店导入
export async function storeImportant (data) {
  return request(`${BASE_URL}/business/admin/storeInfo/import/storeInfosFilterExcel`, METHOD.POST, data)
}

// 格局门店ID查询用户信息
export async function storeMembersGet (storeId, data) {
  return request(`${BASE_URL}/member/admin/storeMembers/list/${storeId}`, METHOD.GET, data)
}
// 查询所有省
export async function allParentsGet () {
  return request(`${BASE_URL}/sys/admin/areas/allParents`, METHOD.GET)
}
export async function getChildrenByParentId (parentId) {
  return request(`${BASE_URL}/sys/admin/areas/getChildrenByParentId`, METHOD.GET, { parentId: parentId })
}
// 门店星级详情
export async function getStoreStars (id) {
  return request(`${BASE_URL}/member/admin/experiences/getExperienceInfoForStore`, METHOD.GET, { storeId: id })
}

// 站点列表
export async function siteList (data) {
  return request(`${BASE_URL}/business/admin/storeSite/page`, METHOD.POST, data)
}
// 上传站点图片
export function uploadSiteImage () {
  return `${BASE_URL}/business/admin/storeSite/image`
}
// 站点删除
export async function deleteSite (id) {
  return request(`${BASE_URL}/business/admin/storeSite/${id}`, METHOD.DELETE)
}
// 站点启用停用
export async function ableSite (id, data) {
  return request(`${BASE_URL}/business/admin/storeSite/${id}/enable`, METHOD.GET, data)
}
// 查看站点详情
export async function siteDetail (id) {
  return request(`${BASE_URL}/business/admin/storeSite/${id}`, METHOD.GET)
}
// 新增站点
export async function addSite (data) {
  return request(`${BASE_URL}/business/admin/storeSite`, METHOD.POST, data)
}
// 修改站点
export async function editSite (data) {
  return request(`${BASE_URL}/business/admin/storeSite`, METHOD.PUT, data)
}
// 查询所有站点-无分页
export async function allSiteList () {
  return request(`${BASE_URL}/business/admin/storeSite/findAllSite`, METHOD.GET)
}
// 所有资产方列表
export async function assetListAll () {
  return request(`${BASE_URL}/business/admin/companies/assetList`, METHOD.GET)
}
// 企业列表-关联资产方-列表
export async function relevanceAssetList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/company/list`, METHOD.GET, data)
}
// 企业列表-关联资产方-资产车辆明细
export async function assetVehicleList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/company/vehicleList`, METHOD.GET, data)
}
// 企业列表-资产明细-列表
export async function assetDetailList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/assetCompany/list`, METHOD.GET, data)
}
// 企业列表-资产明细-列表-运营企业对应门店列表
export async function opCompanyStoreList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/assetCompany/storeList`, METHOD.GET, data)
}
// 企业列表-资产明细-列表-统计信息
export async function opCompanyStatistics (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/statistics`, METHOD.GET, data)
}
// 企业列表-资产明细-列表-资产车辆明细
export async function opCompanyasseVehicleList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/assetCompany/vehicleList`, METHOD.GET, data)
}
// 门店列表-门店详情-关联换电卡列表
export async function storeChangeBatteryList (data) {
  return request(`${BASE_URL}/order/admin/regularStore/associateBatteryCard`, METHOD.GET, data)
}
// 门店列表-门店详情-关联资产方列表
export async function storeAssetList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/store/assetList`, METHOD.GET, data)
}
// 门店列表-门店详情-关联资产方列表-资产车辆
export async function storeAssetCarList (data) {
  return request(`${BASE_URL}/business/admin/qq/asset/store/vehicleList`, METHOD.GET, data)
}
// 1.6.9 分页查询经销商相关信息 1.6.9 LS
export async function getDealer (data) {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo`, METHOD.GET, data)
}
// 1.6.9 不分页查询经销商相关信息 1.6.9 LS
export async function getAllDealer () {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo/all`, METHOD.GET)
}
// 1.6.9 新增或修改经销商相关信息
export async function addorEditDealer (data) {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo`, METHOD.POST, data)
}
// 1.6.9 获取单个经销商信息
export async function getOneDealer (id) {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo/${id}`, METHOD.GET)
}
// 1.6.9 删除经销商信息
export async function delDealer (id) {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo/${id}`, METHOD.DELETE)
}
// 1.6.9 经销商导出
export const dealerExport = (params) => {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    timeout: 60 * 1000,
    url: `${BASE_URL}/business/admin/customer/dealerInfo/export`,
    responseType: 'blob',
    params
  })
}
// 1.6.9 经销商修改状态
export async function dealerChange (id, data) {
  return request(`${BASE_URL}/business/admin/customer/dealerInfo/updateStatus/${id}`, METHOD.GET, data)
}
// 1.7.0 门店列表导出
export const storeExport = (params) => {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    timeout: 60 * 1000,
    url: `${BASE_URL}/business/admin/stores/export`,
    responseType: 'blob',
    params
  })
}
